//引入网络库
import { get, post } from "../../util/util.js"

// 获取全局应用程序实例对象
var app = getApp();

// 创建页面实例对象
Page({
  /**
   * 页面名称
   */
  name: "msg",
  /**
   * 页面的初始数据
   */

  data: {
    uid: '',
    //上下拉
    newlist: {},
    pagesize: 1,
    loading: false,
    role: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },

  onLoad: function (o) {
    var that = this;
    that.setData({
      uid: o.uid,
    })
    wx.getStorage({
      key: 'login',
      success: function (res) {
        var data = res.data
        that.setData({
          role: data.data.role,
        })
        console.log("realAuth====" + data.data.realAuth);
        if (data.data.role == 2) {//艺人
          post("/message/getRecvInviteList", { uid: that.data.uid }).then(data => {
            console.log('getRecvInviteList====================' + JSON.stringify(data.data));
            that.setData({
              newlist: data.data
            })
          })
        } else if (data.data.role == 4) {
          post("/message/getSendInviteList", { uid: that.data.uid }).then(data => {
            console.log('getRecvInviteList====================' + JSON.stringify(data.data));
            that.setData({
              newlist: data.data
            })
          })
        }
      },
    })
  },
  /** 
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },


  //以下为自定义点击事件
  intent: function (e) {
    var that = this;
    var uid = that.data.uid;
    var id = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    console.log("用户跳转传值===" + uid);
    if (that.data.role == 2) {
      wx.navigateTo({
        url: '../msgdetail/msgdetail?uid=' + uid + '&id=' + id,
      })
    } else if (that.data.role == 4) {
      if (status == 5) {
        wx.navigateTo({
          url: '../msgdetail/msgdetail?uid=' + uid + '&id=' + id,
        })
      }
    }

  },
  formatNumber: function (n) {
    n = n.toString()
    return n[1] ? n : '0' + n
  },
  formatTime: function (date) {
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()

    var hour = date.getHours()
    var minute = date.getMinutes()
    var second = date.getSeconds()


    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  },
  /** 
 * 时间戳转化为年 月 日 时 分 秒 
 * number: 传入时间戳 
 * format：返回格式，支持自定义，但参数必须与formateArr里保持一致 
*/
  formatTimeTwo: function (number, format) {

    var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
    var returnArr = [];

    var date = new Date(number * 1000);
    returnArr.push(date.getFullYear());
    returnArr.push(formatNumber(date.getMonth() + 1));
    returnArr.push(formatNumber(date.getDate()));

    returnArr.push(formatNumber(date.getHours()));
    returnArr.push(formatNumber(date.getMinutes()));
    returnArr.push(formatNumber(date.getSeconds()));

    for (var i in returnArr) {
      format = format.replace(formateArr[i], returnArr[i]);
    }
    return format;
  }


})

